<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:lv="FlexListViewer.ListViewerObjectModel" exclude-result-prefixes="lv">

	<!-- URL to the current page (page containing the FlexListViewer-webpart) -->
	<xsl:param name="currentPage"></xsl:param>
	<!-- URL to the current site (site where the current page is hosted) -->
	<xsl:param name="currentSiteUrl">CURRENTSITEURL_X</xsl:param>
	<!-- Locale-id of the current site -->
	<xsl:param name="lcid">LCID</xsl:param>
	<!-- Whether AddNewItem-option must be displayed -->
	<xsl:param name="allowAddNewItem">False</xsl:param>
	<!-- Message to display for the AddNewItem-button/label -->
	<xsl:param name="msgAddNewItem">ADDNEWITEM</xsl:param>
	<!-- Text for "Yes" in the locale of current site -->
	<xsl:param name="msgYes">Ja</xsl:param>
	<!-- Text for "No" in the locale of current site -->
	<xsl:param name="msgNo">Nee</xsl:param>
	
	<!-- Optional parameters that can be used for any purpose you like. -->
	<xsl:param name="param1" />
	<xsl:param name="param2" />
	<xsl:param name="param3" />
	<xsl:param name="param4" />
	<xsl:param name="param5" />

	<xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes"/>
	
	<xsl:template match="/lv:ListView">
		<table border="0" cellspacing="0" cellpadding="0" class="ms-summarytable" width="100%">
		<!-- Header-row -->
		<tr>
			<xsl:apply-templates select="lv:Fields/lv:ListViewField[@Hidden = 'false']" mode="renderField" />
		</tr>
		<!-- Data rows -->
		<xsl:apply-templates select="lv:Rows/lv:ListViewRow/lv:RowValues">
			<xsl:with-param name="fields" select="lv:Fields"/>
		</xsl:apply-templates>
		</table>
		
		<!-- Add new Item -->
		<xsl:if test="$allowAddNewItem = 'True'">
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr height="1px"><td class="ms-partline" style="height:1px;"></td></tr>
				<tr><br/><td style="padding-bottom: 3px">
					&#160;&#160;<img src="/_layouts/images/rect.gif" alt="" />&#160;
					<a href="{@SiteUrl}{@NewFormUrl}?Source={$currentPage}" target="_self">
						<xsl:value-of select="$msgAddNewItem"/>
					</a>
				</td></tr>
			</table>
		</xsl:if>
	</xsl:template>
	
	<!-- Header-row item -->
	<xsl:template match="lv:ListViewField" mode="renderField">
		<td class="ms-vh2">
			<xsl:choose>
				<xsl:when test="@Name = 'Attachments'">
					<img border="0" src="/test/_layouts/images/attach.gif"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="replace">
						<xsl:with-param name="input" select="@DisplayName" />
						<xsl:with-param name="find"> </xsl:with-param>
						<xsl:with-param name="replaceWith">&#160;</xsl:with-param>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</td>
	</xsl:template>
	
	<!-- Row -->
	<xsl:template match="lv:ListViewRow/lv:RowValues">
		<xsl:param name="fields"/>
		<!-- -->
		<tr>
			<xsl:variable name="thisRowValues" select="." />
			<xsl:apply-templates select="$fields/lv:ListViewField[@Hidden = 'false']" mode="renderRow">
				
				<xsl:with-param name="itemId" select="../@Id" />
				<xsl:with-param name="rowValues" select="."/>
			</xsl:apply-templates>
		</tr>
	</xsl:template>

	<!-- Row-item -->
	<xsl:template match="lv:ListViewField" mode="renderRow">
		<xsl:param name="itemId"/>
		<xsl:param name="rowValues"/>
		<!-- -->
		<xsl:variable name="currentFieldName" select="@Name"/>
			<xsl:variable name="fieldValueParts" select="$rowValues/lv:ListViewRowValue[@FieldName = $currentFieldName]/lv:Parts"/>

			<xsl:choose>
				<xsl:when test="@FieldType = 'URL'">
					<td class="ms-vb2">
						<xsl:choose>
							<xsl:when test="count($fieldValueParts/lv:ListViewRowValuePart) >= 2">
								<a href="{$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text()}">
									<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[position() = 2]/text()"/>
								</a>
							</xsl:when>
							<xsl:otherwise>
								<a href="{$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text()}">
									<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text()"/>
								</a>
							</xsl:otherwise>
						</xsl:choose>
						&#160;
					</td>
				</xsl:when>
				<xsl:when test="@FieldType = 'User'">
					<td class="ms-vb2">
						<xsl:choose>
							<xsl:when test="count($fieldValueParts/lv:ListViewRowValuePart) >= 2">
								<xsl:variable name="listSiteUrl" select="/lv:ListView/@SiteUrl" />
								<a href="{$listSiteUrl}_layouts/{$lcid}/UserDisp.aspx?ID={$fieldValueParts/lv:ListViewRowValuePart[position() = 2]/text()}&amp;Source={$currentPage}">
									<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text()"/>
								</a>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text()"/>
							</xsl:otherwise>
						</xsl:choose>
						&#160;
					</td>
				</xsl:when>
				<xsl:when test="@FieldType = 'Lookup'">
					<td class="ms-vb2">
						<xsl:choose>
							<xsl:when test="count($fieldValueParts/lv:ListViewRowValuePart) >= 3">
								<xsl:variable name="listSiteUrl" select="/lv:ListView/@SiteUrl" />
								<a href="{$listSiteUrl}{$fieldValueParts/lv:ListViewRowValuePart[position() = 2]/text()}?ID={$fieldValueParts/lv:ListViewRowValuePart[position() = 3]/text()}&amp;Source={$currentPage}">
									<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text()"/>
								</a>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text()"/>
							</xsl:otherwise>
						</xsl:choose>
						&#160;
					</td>
				</xsl:when>
				<xsl:when test="@FieldType = 'Boolean'">
					<td class="ms-vb2">
						<xsl:choose>
							<xsl:when test="$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text() = 'True'"><xsl:value-of select="$msgYes"/></xsl:when>
							<xsl:otherwise><xsl:value-of select="$msgNo"/></xsl:otherwise>
						</xsl:choose>
						&#160;
					</td>
				</xsl:when>
				<xsl:when test="@FieldType = 'Attachments'">
					<td class="ms-vb2">
						<xsl:choose>
							<xsl:when test="$fieldValueParts/lv:ListViewRowValuePart[position() = 1]/text() = '0'">&#160;</xsl:when>
							<xsl:otherwise><img border="0" src="/test/_layouts/images/attach.gif"/></xsl:otherwise>
						</xsl:choose>
						&#160;
					</td>
				</xsl:when>
				<xsl:when test="@FieldType = 'EDIT'">
					<xsl:variable name="editUrl">
						<xsl:value-of select="/lv:ListView/@SiteUrl"/>
						<xsl:value-of select="/lv:ListView/@EditFormUrl"/>
					</xsl:variable>
					<td class="ms-vb2">
						<a href="{$editUrl}?ID={$itemId}&amp;Source={$currentPage}">
							<img src="{$currentSiteUrl}_layouts/images/edititem.gif" border="0" />
						</a>
						&#160;
					</td>
				</xsl:when>
				<xsl:when test="@FieldType = 'DOCICON'">
					<td class="ms-vb-icon">
						<xsl:variable name="displayUrl">
							<xsl:value-of select="/lv:ListView/@SiteUrl"/>
							<xsl:value-of select="/lv:ListView/@DisplayFormUrl"/>
						</xsl:variable>
						<a href="{$displayUrl}?ID={$itemId}&amp;Source={$currentPage}">
							<img src="{$currentSiteUrl}_layouts/images/{$fieldValueParts/lv:ListViewRowValuePart[1]}" border="0" />
						</a>
					</td>
				</xsl:when>
				<xsl:when test="@FieldType = 'FILE'">
					<xsl:variable name="listRootUrl" select="/lv:ListView/@RootUrl" />
					<td class="ms-vb2">
						<a href="{$listRootUrl}{$fieldValueParts/lv:ListViewRowValuePart[1]}" target="_blank">
							<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[1]"/>
						</a>
						&#160;
					</td>
				</xsl:when>
				<xsl:otherwise>
					<td class="ms-vb2">
						<xsl:choose>
							<xsl:when test="@LinkToItem = 'true'">
								<xsl:variable name="displayUrl">
									<xsl:value-of select="/lv:ListView/@SiteUrl"/>
									<xsl:value-of select="/lv:ListView/@DisplayFormUrl"/>
								</xsl:variable>
								<a href="{$displayUrl}?ID={$itemId}&amp;Source={$currentPage}">
									<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[1]"/>
								</a>
							</xsl:when>											
							<xsl:otherwise>
								<xsl:value-of select="$fieldValueParts/lv:ListViewRowValuePart[1]"/>
							</xsl:otherwise>
						</xsl:choose>
						&#160;
					</td>
				</xsl:otherwise>
			</xsl:choose>
	</xsl:template>

	<xsl:template name="replace">
		<xsl:param name="input"/>
		<xsl:param name="find"/>
		<xsl:param name="replaceWith"/>
		<!-- -->
		<xsl:choose>
			<xsl:when test="$find and contains($input,$find)">
				<xsl:value-of select="substring-before($input, $find)"/>
				<xsl:value-of select="$replaceWith"/>
				<xsl:call-template name="replace">
					<xsl:with-param name="input" select="substring-after($input, $find)"/>
					<xsl:with-param name="find" select="$find"/>
					<xsl:with-param name="replaceWith" select="$replaceWith"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$input"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
		
</xsl:stylesheet>